package ua.edu.nuos.jeetraining2012.cms.util.google.api.services.youtube;

import com.google.api.client.googleapis.media.MediaHttpUploader;
import com.google.api.client.googleapis.media.MediaHttpUploaderProgressListener;
import org.slf4j.Logger;

import java.io.IOException;

/**
 * Define listener for uploading progress.
 *
 * @author Victor N. Ganichev victor.ganichev@gmail.com
 * @version 1.0 Date: 09.06.13 Time: 21:12
 * @since 1.0
 */
public class YouTubeUploadProgress implements MediaHttpUploaderProgressListener {

    /** Define logger. */
    private static Logger logger = org.slf4j.LoggerFactory.getLogger(YouTubeUploadProgress.class);

    @Override
    public void progressChanged(MediaHttpUploader uploader) throws IOException {
        switch (uploader.getUploadState()) {
            case INITIATION_STARTED:
                logger.info("Initiation Started");
                break;
            case INITIATION_COMPLETE:
                logger.info("Initiation Completed");
                break;
            case MEDIA_IN_PROGRESS:
                logger.info("Upload in progress. Upload percentage: {}", uploader.getProgress());
                break;
            case MEDIA_COMPLETE:
                logger.info("Upload Completed!");
                break;
            case NOT_STARTED:
                logger.info("Upload Not Started!");
                break;
        }
    }
}
